//
//  BIZSitcomTeacherInfoCell.m
//  biz
//
//  Created by zhangfuwei on 2017/3/30.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZSitcomTeacherInfoCell.h"
#import "BIZMoviePlaySitcomListDataModel.h"

//static CGFloat kVideoWatchNumLabH = 29;
static CGFloat middleMargin = 8; // 15
static CGFloat largeMargin = 10; // 18
static CGFloat smallMargin = 5; // 10

static NSString *const kConsulorDefaultName = @"咨询师";
static NSString *const kConsulorDefaultDuty = @"律师";

static NSString *const kConsulorDefaultIntroduce = @"待完善中...";


@implementation BIZSitcomTeacherInfoCell {
    UIImageView *_teacherAvatarView;
    UILabel     *_teacheNameLab;
    UILabel     *_teacheDutyLab;
    UILabel     *_teacheDetailInfoLab;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self loadUI];
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    };
    return self;
}

- (void)loadUI {
    
    _teacherAvatarView = [[UIImageView alloc] init];
    _teacherAvatarView.layer.cornerRadius = smallMargin;
    _teacherAvatarView.clipsToBounds = YES;
    
    _teacheNameLab          = [[UILabel alloc]init];
    _teacheDutyLab          = [[UILabel alloc] init];
    _teacheDetailInfoLab    = [[UILabel alloc] init];
    _teacheDetailInfoLab.numberOfLines = 0;
    
    _teacheNameLab.font         =   CHINESE_SYSTEM(14);
    _teacheDutyLab.font         =   CHINESE_SYSTEM(13);
    _teacheDetailInfoLab.font   =   CHINESE_SYSTEM(14);
    
    _teacheNameLab.textColor        =   COLOR_WORD_BLACK;
    _teacheDutyLab.textColor        =   COLOR_WORD_GRAY_1;
    _teacheDetailInfoLab.textColor  =   COLOR_WORD_BLACK;
    
    
    [self.contentView addSubview:_teacherAvatarView];
    [self.contentView addSubview:_teacheNameLab];
    [self.contentView addSubview:_teacheDutyLab];
    [self.contentView addSubview:_teacheDetailInfoLab];
}


- (void)layoutSubviews {
    [super layoutSubviews];
    // 约束布局
    _teacherAvatarView.frame = CGRectMake(middleMargin, largeMargin, 45, 45);
    
    // 教师姓名
    [_teacheNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_teacherAvatarView.mas_right).offset(largeMargin);
        make.top.equalTo(_teacherAvatarView).offset(smallMargin);
        make.right.equalTo(self.contentView).offset(-1*middleMargin);
        make.height.equalTo(@(14));
    }];
    
    // 职责
    [_teacheDutyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(_teacheNameLab);
        make.bottom.equalTo(_teacherAvatarView.mas_bottom).offset(-1*smallMargin);
    }];
    
    // 详情
    [_teacheDetailInfoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_teacherAvatarView);
        make.top.equalTo(_teacherAvatarView.mas_bottom).offset(largeMargin);
        make.bottom.equalTo(self.contentView).offset(-1*middleMargin);
        make.right.equalTo(self.contentView).offset(-1*middleMargin);
    }];
}

#pragma mark -- set方法
-(void)setDataM:(BIZMoviePlaySitcomListDataModel *)dataM {
    _dataM = dataM;
    [_teacherAvatarView sd_setImageWithURL:[NSURL URLWithString:dataM.teacherHeadImg] placeholderImage:[UIImage imageNamed:@"default-head"]];
    _teacheNameLab.text = dataM.teacherName?:kConsulorDefaultName;
    _teacheDutyLab.text = dataM.duty?:kConsulorDefaultDuty;
    _teacheDetailInfoLab.text = dataM.teacherIntroduce?:kConsulorDefaultIntroduce;
    
    [self layoutIfNeeded];

}

@end
